<!DOCTYPE html>
{extend name="common/application" /}
{block name="title"}<title>店铺中心-订单管理</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/help.css" />
<link rel="stylesheet" type="text/css" href="_CSS_/store_center.css"/>
<style type="text/css">
	.item-content .item-title{
		height: 78px;
	}
	.nodatas{text-align:center;padding:100px 0;width:850px;}
	.nodatas img{margin:100px 0 50px 0;}
</style>
{/block}
<!-- 主体内容 -->
{block name="content"}
			<!-- 主体内容 -->
			<div class="main">
				<div class="mainBody normalBox clearfix">
					<!--左菜单-->
					{include file="/common/left" /}
					<!--右内容-->
					<div class="menuContent fr">
						<div class="menuConHeader">
							<!--面包屑导航-->
							<div class="breadcrumb">
								<p>
									<a href="javascript:;">订单管理</a> &gt;
									<a class="curPage" href="{:url('index/store/orders')}">订单管理</a>
								</p>
							</div>
						</div>
						<div class="menuConBody">
							<div class="courseMenu">							
								<div class="courseSelect">
									<ul>
										<li>
											<a class="selectType" href="{:url('index/store/orders')}">交易类商品</a>
										</li>
										<li class="selected">
											<a class="selectType" href="javascript:;">服务类商品</a>
										</li>
									</ul>
								</div>
								<div class="conBody">
                                    <div class="orders-main">
                                        <!-- 订单状态分类 -->
                                        <div class="orders-status">
                                        	<ul>
                                        		<li class="action">全部订单<span></span></li>
                                        		<li>待支付<span></span></li>
                                        		<li>待上传<span></span></li>
                                        		<li>待确认<span></span></li>
                                        		<li>待退款<span></span></li>
                                        		<li>待评价<span></span></li>
                                        		<li>已完成<span></span></li>
                                        		<li>已取消<span></span></li>
                                        	</ul>
                                        </div>
                                        <!--查询不出数据-->
										<div class="nodatas" style="display: none;">
											<img src="_IMG_/nocart.png"/>
											<p>抱歉，暂无订单</p>
										</div>
										<div class="orders-table-th">
											<div class="orders-wp">
												<div class="orders-th th-item">
													<div class="td-inner">商品信息</div>
												</div>
												<div class="orders-th th-type">
													<div class="td-inner">&nbsp;</div>
												</div>
												<div class="orders-th th-price">
													<div class="td-inner">商品金额</div>
												</div>
												<div class="orders-th th-status">
													<div class="td-inner">订单状态</div>
												</div>
												<div class="orders-th th-op">
													<div class="td-inner">操作</div>
												</div>
											</div>
										</div>
										<div class="orders-box">
											<div style="height: auto;" id="service">


											</div>
										</div>
                                    </div>


								</div>
							</div>
						</div>
						<div id="page">

						</div>
					</div>
				</div>
			</div>
{/block}



{block name="js"}
		<script src="_P_/layer/layer.js"></script>
<script src="_JS_/time.js"></script>
		<script>
		    $(document).ready(function () {
		        $('.li3').addClass('showChild');
		        $('.li30').addClass('activeMenu');
		    });
			$(document).ready(function(){
				order_service(1);
				//订单状态选择
				$('.orders-status li').on('click',function(){
					if($(this).hasClass('action')){
						return false;
					}else{
						$('.orders-status .action').removeClass('action');
						$(this).addClass('action');
					}
				})
				/*二级导航*/
				$('.selectType').on('click',function(){
					$('.selectType').parent().removeClass('selected');
					$(this).parent().addClass('selected');
					order_service(1);
				});
			});


			//上传合同
			function upload_contract(id){
				layer.open({
				  type: 2,
				  title:'上传合同',
				  skin: 'layui-layer-lan',
				  area: ['610px', '400px'], //宽高
				  content: 'upload_contract.html#'+id
				});
			}
			//上传快递单号
			function upload_tracking(id){
				layer.open({
				  type: 2,
				  title:'上传快递单号',
				  skin: 'layui-layer-lan',
				  area: ['570px', '400px'], //宽高
				  content: 'mail.html#'+id
				});
			}
			//查看快递信息
			function check_tracking(id){
				layer.open({
				  type: 2,
				  title:'查看快递信息',
				  skin: 'layui-layer-lan',
				  area: ['570px', '150px'], //宽高
				  content: 'check_tracking.html#'+id
				});
			}
			//确认收货
			function confirm_receipt(id){
				var userinfo=$.cookie('userinfo');
				if(userinfo) {
					var user_login = $.base64.decode(userinfo).split(",");
					var user_uid = user_login[0];
					$.ajax({
						type: "get",
						url: "/index.php/api/form/user_detail",
						data: {
							'uid': user_uid
						},
						dataType: 'jsonp',
						success: function (msg) {
							if (msg.code == 200) {
								if (msg.data.code != null && msg.data.code != '') {
									layer.open({
										type: 2,
										title: '确认收货',
										skin: 'layui-layer-lan',
										area: ['570px', '360px'], //宽高
										content: 'confirm_receipt.html?id=' + id + '&type=2'
									});
								} else {
									layer.msg('还未设置支付密码，即将前往个人中心设置', {icon: 5}, function () {
										window.location.href = "/index.php/index/person/account";
									});
								}
							} else {
								layer.msg(msg.message, {icon: 5});
							}
						}
					});
				}else{
					layer.msg('还未登录', {icon: 5});
				}
			}
			//确认收款
			function confirmation_receivables_ser(id){
				layer.open({
				  type: 2,
				  title:'确认收款',
				  skin: 'layui-layer-lan',
				  area: ['570px', '360px'], //宽高
				  content: 'confirmation_receivables_ser.html?id='+id+'&type=2'
				});
			}
			//评价
			function appraise(id){
				layer.open({
				  type: 2,
				  title:'评价',
				  skin: 'layui-layer-lan',
				  area: ['570px', '480px'], //宽高
				  content: 'appraise.html?id='+id+'&type=2'
				});
			}
			//申诉
			function appeal(id){
				layer.open({
				  type: 2,
				  title:'申诉',
				  skin: 'layui-layer-lan',
				  area: ['690px', '700px'], //宽高
				  content: 'appeal.html#'+id
				});
			}

			//退款
			function refund(id){
				layer.open({
				  type: 2,
				  title:'退款',
				  skin: 'layui-layer-lan',
				  area: ['570px', '360px'], //宽高
				  content: 'refund.html#'+id
				});
			}

			/*查看详情*/
			function view_detials(id){
				window.location.href='order_details.html?id='+id+'=2';
			}
			$('.orders-status li').on('click',function(){
				$('.orders-status li').removeClass('action');
				$(this).addClass('action');
				order_service(1);
			});
			function order_service(page){
				var userinfo=$.cookie('userinfo');
				if(userinfo) {
					var user_login = $.base64.decode(userinfo).split(",");
					var user_uid = user_login[0];
//					var sheet =parseInt($(".courseSelect li").index($(".courseSelect li[class='selected']")))+1 ;
					var index = $('.orders-status li').index($('.orders-status li[class="action"]'));
					var order;
					switch (parseInt(index)) {
						case 1:
							order = '1';
							break;
						case 2:
							order = '2,4';
							break;
						case 3:
							order = '5,7,9';
							break;
						case 4:
							order = '12';
							break;
						case 5:
							order = '10';
							break;
						case 6:
							order = '11';
							break;
						case 7:
							order = '13,14';
							break;
						default:
							order = 0;
							break;
					}
					$.ajax({
						type: "get",
						url: "/index.php/api/form/order_index",
						data: {'uid': user_uid, 'page': page, 'order': order,'sheet':2},
						dataType: 'jsonp',
						success: function (msg) {
							var total=0;var pay_num=0;var confirm_num=0;var upload_num=0;
								var refund_num=0;var ment_num=0;var over_num=0;var cancle_num=0;
								if(msg.data.num){
									for(var j=0;j<msg.data.num.length;j++){
										if(msg.data.num[j].status!=0){
											total+=parseInt(msg.data.num[j].num);
										}
										if(msg.data.num[j].status==1){
											pay_num=parseInt(msg.data.num[j].num);
										}
										if(msg.data.num[j].status==2||msg.data.num[j].status==4){
											upload_num=parseInt(msg.data.num[j].num);
										}
										if(msg.data.num[j].status==5||msg.data.num[j].status==7||msg.data.num[j].status==9){
											confirm_num+=parseInt(msg.data.num[j].num);
										}
										if(msg.data.num[j].status==12){
											refund_num=parseInt(msg.data.num[j].num);
										}
										if(msg.data.num[j].status==10){
											ment_num=parseInt(msg.data.num[j].num);
										}
										if(msg.data.num[j].status==11){
											over_num+=parseInt(msg.data.num[j].num);
										}
										if(msg.data.num[j].status==14||msg.data.num[j].status==13){
											cancle_num+=parseInt(msg.data.num[j].num);
										}
									}
								}
								$('.orders-status').find('ul li span').eq(1).html(pay_num);
								$('.orders-status').find('ul li span').eq(2).html(upload_num);
								$('.orders-status').find('ul li span').eq(3).html(confirm_num);
								$('.orders-status').find('ul li span').eq(4).html(refund_num);
								$('.orders-status').find('ul li span').eq(5).html(ment_num);
								$('.orders-status').find('ul li span').eq(6).html(over_num);
								$('.orders-status').find('ul li span').eq(7).html(cancle_num);
								
							if (msg.code == 200) {
								var html="";
								
								for(var i=0;i<msg.data.data.length;i++){
									var money = number_format(msg.data.data[i].money, 2, ".", ",");
									html+='<div class="clearfix order-body"><div class="orders clearfix"><div class="orders-info">';
									html+='<p><span>'+getMyDate(msg.data.data[i].time*1000)+'</span><span>订单编号：'+msg.data.data[i].order+'</span><span>买家ID：'+msg.data.data[i].user+'</span>';
									html+='</p></div></div>';
									html+='<div class="orders-content"><div class="item-list"><div class="bundle  bundle-last ">';
									html+='<div class="item-holder"><div class="J_ItemBody item-body clearfix item-normal  first-item">';
									html+='<ul class="item-content clearfix">';
									html+='<li class="orders-td td-item"><div class="td-inner">';
									html+='<div class="item-pic J_ItemPic img-loaded"><a href="/index.php/index/service/service_details.html?id='+msg.data.data[i].s_id+'" target="_blank"  class="J_MakePoint" data-point="tbcart.8.12">';
									html+='<img src="/Images/serviceGoods/'+msg.data.data[i].pic+'" class="itempic J_ItemImg"></a></div>';
									html+='<div class="item-info"><div class="item-basic-info">';
									html+='<a href="/index.php/index/service/service_details.html?id='+msg.data.data[i].s_id+'" target="_blank" title="" class="item-title J_MakePoint" data-point="tbcart.8.11">'+msg.data.data[i].goods_name+'</a>';
									html+='</div><div class="item-other-info"><div class="item-icon-list clearfix">';
									html+='<span>服务分类：'+msg.data.data[i].t_name+'</span></div></div></div></div></li>';
									html+='<li class="orders-td td-type"><div class="item-props item-props-can"><p class="sku-line" tabindex="0">服务类商品</p></div></li>';
									html+='<li class="orders-td td-price"><div class="td-inner"><div class="item-price price-promo-">';
									html+='<div class="price-content"><div class="price-line"><span class="price-now">￥'+ money +'</span>';
									html+='</div></div></div></div></li>';
									if(msg.data.data[i].status==1){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>订单已提交， 等待买家付款</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"><p>'+dateDiff(msg.data.data[i].time)+'</p></div></li>';
									}else if(msg.data.data[i].status==2){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>买家已付款，上传合同</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"  class="J_Del J_MakePoint" onclick="upload_contract('+msg.data.data[i].id+')">上传合同</a></div></li>';
									} else if(msg.data.data[i].status==3){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>等待买家下载合同</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"></div></li>';
									}else if(msg.data.data[i].status==4){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>上传新合同</p><span style="color: red;font-size: 12px;">注:只能上传三次</span><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"  class="J_Del J_MakePoint" onclick="upload_contract('+msg.data.data[i].id+')">上传新合同</a><p><a title="申诉" href="javascript:;" class="J_Del J_MakePoint" onclick="appeal('+msg.data.data[i].id+')">申诉</a></p></div></li>';
									}else if(msg.data.data[i].status==5){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>买家已确认合同，等待上传快递单号</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"  class="J_Del J_MakePoint" onclick="upload_tracking('+msg.data.data[i].id+')">上传快递单号</a></div></li>';
									}else if(msg.data.data[i].status==6){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>已上传快递单号，待平台确认收货并邮寄</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"></div></li>';
									}else if(msg.data.data[i].status==7){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>平台审核通过，等待确认收货</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"  class="J_Del J_MakePoint" onclick="check_tracking('+msg.data.data[i].id+')">查看快递单号</a><a href="javascript:;"  class="J_Del J_MakePoint cl-g" onclick="confirm_receipt('+msg.data.data[i].id+')">确认收货</a><p><a title="申诉" href="javascript:;" class="J_Del J_MakePoint" onclick="appeal('+msg.data.data[i].id+')">申诉</a></p></div></li>';
									}else if(msg.data.data[i].status==8){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>待平台打款</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"></div></li>';
									}else if(msg.data.data[i].status==9){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>	平台已打款，等待商家确认收款</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"  class="J_Del J_MakePoint cl-g" onclick="confirmation_receivables_ser('+msg.data.data[i].id+')">确认打款</a></div></li>';
									}else if(msg.data.data[i].status==10){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>商家已确认收款，等待评价</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"  class="J_Del J_MakePoint" onclick="appraise('+msg.data.data[i].id+')">评价</a></div></li>';
									}else if(msg.data.data[i].status==12){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>订单待退款</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"  class="J_Del J_MakePoint cl-r" onclick="refund('+msg.data.data[i].id+')">确认退款</a></div></li>';
									} else if(msg.data.data[i].status==11){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>已评价,订单结束</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"></div></li>';
									}else if(msg.data.data[i].status==13){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>订单已退款</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"></div></li>';
									}else if(msg.data.data[i].status==14){
										html+='<li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
										html+='<p>订单已取消</p><p>';
										html+='<a title="查看详情" href="#" onclick="view_detials('+msg.data.data[i].id+')">查看详情</a></p></div></li>';
										html+='<li class="orders-td td-op"><div class="td-inner"></div></li>';
									}

									html+='</ul></div></div></div></div></div></div>';
								}
								$('#service').html(html);
								$('#page').html(msg.data.render);
								$("#pagination").delegate("a", "click", function () {
									var num = $(this).attr("num");
									if (num) {
										order_service(num);
									}
								});
								$('.orders-status').find('ul li span').eq(0).html(total);								
							}
							if (msg.code == 1000) {
								$('.orders-table-th').css('display','none');
								$('#service').html('<div class="nodatas" ><img src="/static/web/images/nodatas01.png"/><p>抱歉，暂无订单</p></div>');
								$('#page').html('');
							}
						}
					});
				}else{
					layer.msg('还未登录！', {icon: 51});
				}
			}
			/**格式化剩余时间**/
			var dateDiff = function (timestamp) {
				// 补全为13位
				var arrTimestamp = (timestamp + '').split('');
				for (var start = 0; start < 13; start++) {
					if (!arrTimestamp[start]) {
						arrTimestamp[start] = '0';
					}
				}
				timestamp = arrTimestamp.join('') * 1;

				var minute = 1000 * 60;
				var hour = minute * 60;
				var day = hour * 24;

				var now = new Date().getTime();
				var Value = now - timestamp;
				var diffValue = day - Value;

				// 如果本地时间反而小于变量时间
				if (diffValue < 0) {
					return '订单已失效';
				}
				var dayC = diffValue / day;
				var hourC = diffValue / hour;
				var minC = diffValue / minute;

				// 数值补0方法
				var zero = function (value) {
					if (value < 10) {
						return '0' + value;
					}
					return value;
				};
				// 使用
				if (dayC >= 1 ) {
					// 超过1天，直接显示年月日
					/****return (function () {
						//var date = new Date(timestamp);
						//return "剩余"+date.getFullYear() + '年' + zero(date.getMonth() + 1) + '月' + zero(date.getDate()) + '日';
					})();**/
					return "剩余23小时";
				} else if (hourC >= 1) {
					return "剩余"+parseInt(hourC) + "小时";
				} else if (minC >= 1) {
					return "剩余"+parseInt(minC) + "分钟";
				}
			};
		</script>
{/block}
			